<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>交易明细</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" media="all">
    <style>
        .transactionDetail-container {
            padding: 20px;
        }

        td[data-field="imgUrl"] div,
        td[data-field="negativeImgUrl"] div {
            height: 120px;
        }

        .lay-form {
            padding: 20px;
        }

        .transactionDetail-container {
            background-color: #fff;
        }

        .bar {
            display: flex;
            justify-content: flex-start;
            align-items: flex-end;
        }

        .searchInput {
            display: flex;
            align-items: flex-end;
        }

        .searchInput label {
            font-size: 12px;
        }

        .searchInput input {
            width: 200px;
        }

    </style>
</head>

<body>
    <div class="transactionDetail-container">
        <!-- 搜索 -->
        <div class="searchInput">
            <form class="layui-form" action="" lay-filter="resets">
                <div class="layui-inline">
                    <label class="layui-form-label">昵称：</label>
                    <input class="layui-input" name="userName" placeholder="请输入客户昵称" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">客户手机：</label>
                    <input class="layui-input" name="userPhone" placeholder="请输入客户手机号" autocomplete="off">
                </div>
                <!-- 筛选 -->
                <div class="layui-inline">
                    <div class="layui-form-item" id="status" style="margin-bottom:0">
                        <label class="layui-form-label" style="text-align:right; font-size:10px;padding: 9px 0;">订单类型：</label>
                        <div class="layui-input-block" style="margin-left: 80px; margin-top: 0px;">
                            <select name="orderType" lay-filter="select">
                                <option value="">全部</option>
                                <option value="1">商品订单</option>
                                <option value="2">分销商订单</option>
                                <option value="3">提现订单</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">交易编号：</label>
                    <input class="layui-input" name="payNo" placeholder="请输入交易编号" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">交易时间：</label>
                    <input type="text" class="layui-input" id="test1" name="time" placeholder="交易时间" autocomplete="off">
                </div>
                <button class="layui-btn" data-type="reload" lay-submit="" lay-filter="searchForm">搜索</button>
                <button class="layui-btn layui-btn-primary" data-type="reload" lay-submit=""
                    lay-filter="reset">重置</button>
            </form>
        </div>

        <table lay-filter="transactionDetailTable" class="layui-hide" id="transactionDetailTable"></table>
    </div>

</body>

<script src="https://cdn.bootcdn.net/ajax/libs/layui/2.5.7/layui.all.min.js"></script>
<script src="../utils.js"></script>
<script>
    layui.use(['table', 'upload', 'form', 'jquery', "laydate"], function () {
        var table = layui.table,
            upload = layui.upload,
            form = layui.form,
            laydate = layui.laydate,
            $ = layui.jquery;

        table.render({
            elem: '#transactionDetailTable'
            , toolbar: "#toolbarDemo"
            , url: window.baseUrl + '/stat/getTransactionDetail'
            , headers: {
                Authorization: localStorage.token
            }
            , response: {
                statusCode: 200 //规定成功的状态码，默认：0
            }
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 200,
                    "count": res.data.recordsTotal, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            }
            , request: {
                pageName: 'start' //页码的参数名称，默认：page
                , limitName: 'length' //每页数据量的参数名，默认：limit
            }
            , cols: [[
                { field: 'userName', title: '昵称' }
                ,{ field: 'userPhone', title: '客户手机' }
                , { field: 'orderType',title: '订单类型', templet: function(res){
                        return res.orderType == 1 ? "商品订单" : res.orderType == 2 ? "分销商订单" : res.orderType == 3 ? "提现订单" : "-"
                    } }
                , { field: 'orderId',title: '订单编号' }
                , { field: 'amount',title: '交易金额', templet: function(res){
                        return res.amount ? res.amount / 100 + "元" : "-"
                    } }
                , { field: 'payType',title: '交易类型', templet: function(res){
                        return res.payType == '1' ? "支付" : res.payType == '2' ? "退款" : res.payType == '3 '? "提现" : "-"
                    } }
                , { field: 'payNo',title: '交易单号' }

                ,{ field: 'createTime', title: '交易时间' }

            ]],
            page: true
            , done: function () {
        
            }
        });

        laydate.render({
            elem: '#test1'
            ,range: true
        });

        // 搜索
        form.on("submit(searchForm)", function (e) {
            if(e.field.time != ''){
                var a = e.field.time.split(" - ");
                e.field.sDateQuery = new Date(a[0]);
                e.field.eDateQuery = new Date(a[1]);
            }
            for (let key in e.field) {
                if (!e.field[key]) {
                    delete e.field[key]
                }
            }

            // if (e.field.createTime) {
            //     e.field.createTime = new Date(e.field.createTime).getTime()
            // }

            table.reload('transactionDetailTable', {
                page: {
                    start: 1 //重新从第 1 页开始
                }
                , where: e.field
            });

            return false;
        })


        // 搜索
        form.on("submit(reset)", function (e) {

            table.reload('transactionDetailTable', {
                page: {
                    start: 1 //重新从第 1 页开始
                }
                , where: null
            });

            form.val("resets", {
                ordersId: "",
                createTime:""
            });

            return false;
        })

    });
</script>

</html>